package com.yf1706.service;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yf1706.bean.ComprehensiveQuestion;
import com.yf1706.bean.GapFilling;
import com.yf1706.bean.QuestionBank;
import com.yf1706.dao.jpa.comprehensiveJDAO;
import com.yf1706.dao.jpa.questionBankJDAO;
import com.yf1706.dao.mybatis.ComprehensiveMDAO;

@Service
public class comprehensiveService {
	
	@Autowired
	private comprehensiveJDAO chjdao;
	
	@Autowired
	private ComprehensiveMDAO cmdao;
	
	@Autowired 
	private questionBankJDAO qbjdao;
	
	public List<ComprehensiveQuestion> findByQuestionBank(QuestionBank q) {
		return chjdao.findByQuestionBank(q);
	}
	
	public List<ComprehensiveQuestion> querybyQbId(int qbId) {
		return cmdao.querybyQbId(qbId);
	}
	
	//在题库添加题目
	public void questionbankAddComprehensive(String answer,String examQuestion,String qbId,String createPeople){
		ComprehensiveQuestion sc=new ComprehensiveQuestion();
		sc.setAnswer(answer);
		sc.setCreateDate(new Date());
		sc.setExamQuestion(examQuestion);
		sc.setCreatePeople(createPeople);
		int qbid=Integer.parseInt(qbId);
		sc.setQuestionBank(qbjdao.findByQbId(qbid));
		chjdao.save(sc);
	}

	public void deleteQuestionBankComprehensive(int ComprehensiveId) {
		chjdao.deleteById(ComprehensiveId);
		
	}

	public List<ComprehensiveQuestion> queryAllcomprehensive() {
		
		return cmdao.queryAllcomprehensive();
	}

	public List<ComprehensiveQuestion> queryAllByQbIdAndExamQuestion(int qbId, String examQuestion) {
		
		return cmdao.queryAllByQbIdAndExamQuestion(qbId,examQuestion);
	}

	public List<ComprehensiveQuestion> findByComprehensiveQuestionId(int comprehensiveId) {
		
		return chjdao.findByComprehensiveQuestionId(comprehensiveId);
	}

	public void add(String examQuestion, String answer, int qbId, String sessionUserName) {
		ComprehensiveQuestion c=new ComprehensiveQuestion();
		c.setAnswer(answer);
		c.setCreateDate(new Date());
		c.setCreatePeople(sessionUserName);
		c.setExamQuestion(examQuestion);
		c.setQuestionBank(qbjdao.findByQbId(qbId));
		chjdao.save(c);
	}

}
